﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using DomainDriver.DomainModeling.Constraints;
using DomainDriver.DomainModeling.DataProviders;
using DomainDriver.DomainModeling.DomainModels;
using DomainDriver.DomainModeling.Exceptions;
using DomainDriver.DomainModeling.Repositories;
using DomainDriver.DomainModeling.Example;
using DomainDriver.DomainModeling.Example.DomainObjects;
using DomainDriver.DomainModeling.GenericUnitTesting;
using DomainDriver.DomainModeling.GenericUnitTesting.Constraints;

namespace DomainDriver.DomainModeling.UnitTests.Constraints
{
    [TestFixture(new object[] { DataSourcePersistenceType.None })]
    [TestFixture(new object[] { DataSourcePersistenceType.File })]
    [TestFixture(new object[] { DataSourcePersistenceType.Database })]
    public class DummyDomainObjectChildConstraintTests : ListRelationConstraintTestFixture<ExampleDomainModel, Guid, Guid, DummyDomainObject, DummyDomainObject>
    {
        public DummyDomainObjectChildConstraintTests(DataSourcePersistenceType persistenceType)
            : base(persistenceType)
        {
            // do nothing
        }

        protected override ExampleDomainModel CreateDomainModel(DataSourcePersistenceType persistenceType, bool buildModelWithConstraints)
        {
            ExampleDomainModel model = new ExampleDomainModel(persistenceType, buildModelWithConstraints);
            return model;
        }

        protected override DummyDomainObject CreateOwner()
        {
            DummyDomainObject domainObject = new DummyDomainObject();
            domainObject.Name = domainObject.Key.ToString();
            return domainObject;
        }

        protected override DummyDomainObject CreateElement()
        {
            DummyDomainObject domainObject = new DummyDomainObject();
            domainObject.Name = domainObject.Key.ToString();
            return domainObject;
        }

        protected override void AddToList(DummyDomainObject owner, Guid elementKey)
        {
            owner.AddChild(elementKey);
        }

        protected override void RemoveFromList(DummyDomainObject owner, Guid elementKey)
        {
            owner.RemoveChild(elementKey);
        }

        protected override void ClearList(DummyDomainObject owner)
        {
            foreach (Guid elementKey in owner.Children)
            {
                owner.RemoveChild(elementKey);
            }
        }

        protected override int ListCount(DummyDomainObject owner)
        {
            return owner.Children.Count;
        }

        protected override bool ListContains(DummyDomainObject owner, Guid elementKey)
        {
            return owner.Children.Contains(elementKey);
        }
    }
}